package com.sixnimmt.app.server.game.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.sixnimmt.app.shared.game.domain.Card;

public class Deck implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private final List<Card> cards;
	private int cursor;

	public Deck() {
		cards = new ArrayList<Card>();
		addCards(Card.values());
	}

	public void init() {
		cursor = 0;
		shuffle();
	}

	public Card distribute() {
		return cards.get(cursor++);
	}

	private void addCards(Card... addingCards) {
		for (int i = 0; i < addingCards.length; i++) {
			cards.add(addingCards[i]);
		}
	}

	private void shuffle() {
		Collections.shuffle(cards);
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for (Card c : cards) {
			sb.append(c.toString() + "\r\n");
		}
		return sb.toString();
	}

	protected List<Card> getCards() {
		return cards;
	}

}
